package com.bwie.utils;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
 * @description: 项目统一返回对象
 * @author: xushuaihang
 * @Date: 2024/6/17 9:13
 * @param:
 * @param
 * @return:
**/
@Data
public class R implements Serializable {

    private String message;

    private Boolean flag;

    private Integer code;

    private Map<String, Object> data = new HashMap<>();



    public static R error(){
        R r = new R();
        r.setFlag(false);
        r.setCode(2001);
        r.setMessage("失败");
        return r;
    }
    public static R ok(){
        R r = new R();
        r.setFlag(true);
        r.setCode(2000);
        r.setMessage("成功");
        return r;
    }

    public R message(String message) {
        this.message = message;
        return this;
    }

    public R flag(Boolean flag) {
        this.flag = flag;
        return this;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }

    public R data(Map<String, Object> data) {
        this.data.putAll(data);
        return this;
    }
    public R data(String key,Object value) {
        this.data.put(key, value);
        return this;
    }
}
